import { Article } from "@/types/data"
import { ArticleAction } from "@/types/store"

type ArticleType = {
    channelArticles: {
      [key: number]: {
        timestamp: string
        articles: Article[]
      }
    }
  }
const initialState:ArticleType={
    channelArticles:{}
}

const login = (state = initialState, action: ArticleAction):ArticleType => {
  switch(action.type){
    case 'article/get_list':
      const {channel_id,timestamp,articles} =action.payload
      const old = state.channelArticles[channel_id]?.articles || []
            return {...state,channelArticles:{...state.channelArticles,[channel_id]:{timestamp,articles:[...old,...articles]}}}
    // case 'article/addNew_list':
    //         return {...state,channelArticles:{...state.channelArticles,[channel_id]:{timestamp,articles:[...articles]}}}
    default:
            return state
    }
    
}

export default login

